﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.User.Identity.IsAuthenticated)
            Response.Redirect("login.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = TextBox1.Text.Trim();
        if (TextBox1.Text.Length == 0)
        {
            Label1.Text = "请输入班级名称!";
            return;
        }


        string strsql = "SELECT * FROM CLASS WHERE department='" + DropDownList1.Text + "' AND grade='" + DropDownList2.Text + "' AND class='" + TextBox1.Text + "'";
        SqlDataReader sdr = SQLHelper.SQLHelper.ExecReader(strsql);
        if (sdr.Read())
        {
            Label1.Text = "该班级已存在!";
            return;
        }


        try
        {

            strsql = "insert into class (department,grade,class,created,owner) values ('" + DropDownList1.Text + "','" + DropDownList2.Text + "','" + TextBox1.Text + "','" + DateTime.Now + "','" + Page.User.Identity.Name + "')";
            SQLHelper.SQLHelper.ExecNonQuery(strsql);

        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
            return;
        }

        /*添加管理员联系人

        try
        {
            string _user = User.Identity.Name;
            string _class = TextBox1.Text;
            strsql = "update member  set [class]='" + _class + "' where [user]='" + User.Identity.Name +"'";
            SQLHelper.SQLHelper.ExecNonQuery(strsql);
        }
        catch
        {
            Label1.Text = "添加联系人失败!";
            return;
        }
        */

        Panel1.Visible = false;
        Panel2.Visible = true;

        Roles.AddUserToRole(Page.User.Identity.Name, "班级管理员");



        
    }
    protected void XmlDataSource1_Transforming(object sender, EventArgs e)
    {

    }
}